﻿using Comm100.Framework.Domain.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using Bot.Domain.Bo;
using Castle.Windsor;
using Bot.Domain.Specifications;

namespace Bot.Domain.Categories.Service
{
    public class SmartTriggerConditionDomainService : ISmartTriggerConditionDomainService
    {
        private IWindsorContainer _container;
        private readonly IRepository<Guid, SmartTriggerCondition> _repository;

        public SmartTriggerConditionDomainService(IRepository<Guid, SmartTriggerCondition> repository, IWindsorContainer container)
        {
            this._repository = repository;
            this._container = container;
        }

        public SmartTriggerCondition Create(SmartTriggerCondition condition)
        {
            return _repository.Create(condition);
        }

        public SmartTriggerCondition Get(Guid id)
        {
            return _repository.Get(id);
        }

        public SmartTriggerCondition Update(SmartTriggerConditionUpdateBo bo)
        {
            SmartTriggerCondition smartTriggerCondition = _repository.Get(bo.Id);
            //smartTriggerCondition.Id = bo.Id;
            //smartTriggerCondition.SmartTriggerId = bo.SmartTriggerId;
            smartTriggerCondition.Variable = bo.Variable;
            smartTriggerCondition.Expression = bo.Expression;
            smartTriggerCondition.Value = bo.Value;
            smartTriggerCondition.Order = bo.Order;

            _repository.Update(smartTriggerCondition);

            return smartTriggerCondition;

        }

        public IEnumerable<SmartTriggerCondition> List()
        {
            return _repository.ListAll();
        }
        public IEnumerable<SmartTriggerCondition> GetBySmartTriggerId(Guid smartTriggerId)
        {
            return _repository.List(new SmartTriggerConditionFilterSpecification(smartTriggerId));
        }

        public void Delete(Guid id)
        {
            SmartTriggerCondition smartTriggerCondition = _repository.Get(id);

            _repository.Delete(smartTriggerCondition);

        }
    }
}
